<?php

//账龄查询
class AgingApp extends MallbaseApp
{


    function index()
    {
        $searchTypes = array(
            'feeFcheckdate' => '费用记账日期',
            'feecheckdate' => '费用审核日期',
            'feeopdate' => '费用操作日期',
            'operationDate' => '业务操作日期',
        );
        $this->assign('searchTypes', $searchTypes);
        $this->assign('types', array(
            '' => '请选择费用类别',
            '应收' => '应收',
            '应付' => '应付',
        ));
        $data = array();
        $start = date('Y-m-01', strtotime(date("Y-m-d")));
        $end = date('Y-m-d', strtotime(date("Y-m-d")));
        $bdate = empty($_REQUEST['bdate']) ? $start : trim($_REQUEST['bdate']);
        $edate = empty($_REQUEST['edate']) ? $end : trim($_REQUEST['edate']);
        $type = empty($_REQUEST['type']) ? '' : trim($_REQUEST['type']);
        $pageIndex = empty($_REQUEST['pageIndex']) ? 1 : trim($_REQUEST['pageIndex']);
        $searchType = empty($_REQUEST['searchType']) ? 'feeFcheckdate' : trim($_REQUEST['searchType']);
        //$wxNum = empty($_REQUEST['wxNum']) ? '123' : trim($_REQUEST['wxNum']);
        $wxNum = isset($_COOKIE['wxid'])?$_COOKIE['wxid']:'';
        if(empty($wxNum)){
            echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';
            echo "<script>alert('授权未成功');  window.location.href='http://dskc.csrsfwl.com/index.php?app=login'; </script>  ";//使用weixin.php的页面
        }
        if ($this->checkUrl(WEB_SERVICE)) {
            $client = new soapclient(WEB_SERVICE);
            $client->soap_defencoding = 'utf-8';
            $client->decode_utf8 = false;
            $client->xml_encoding = 'utf-8';
            $param = array(
                'json' => '{"pageIndex":"' . $pageIndex . '","bdate":"' . $bdate . '","edate":"' . $edate . '","type":"' . $type . '","searchType":"' . $searchType . '","wxNum": "' . $wxNum . '"}');

            $result = $client->__Call("AgingList", array($param));

            if (is_soap_fault($result)) {
                trigger_error("SOAP Fault: (faultcode: {$result->faultcode}, faultstring: {$result->faultstring})", E_USER_ERROR);
            } else {
                $result = json_decode(json_encode($result->AgingListResult), TRUE);
                $result = preg_replace('/([\r\n])/', '', $result);
                $result = json_decode($result, true);
                if ($result['status'] == 1) {
                    $data = $result['result'];
                    $dataCount = $result['dataCount'];
                } else {
                    if ($result['result'] == '该用户未登录') {
                        echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';
                        echo "<script>alert('请先绑定微信'); window.location.href='index.php?app=login&hist=payment&wxNum=".$wxNum."'; </script>  ";
                        exit();
                    } elseif (strstr($result['result'], '该用户无权')) {
                        echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';
                        echo "<script>alert('$result[result]'); window.location.href='index.php?app=menu'; </script>  ";
                        exit();
                    }
                }

            }
        }
        $this->import_resource(array('script' => 'jquery.ui/jquery.ui.js,jquery.ui/i18n/' . i18n_code() . '.js',
            'style' => 'jquery.ui/themes/ui-lightness/jquery.ui.css'));
        $this->assign('bdate', $bdate);
        $this->assign('edate', $edate);
        $this->assign('searchType', $searchType);
        $this->assign('type', $type);
        if($data)
        {
            $this->assign('agings', $data);
            $page = $this->_get_page();
            $page['item_count'] = $dataCount;
            $this->_format_pageweb($page);
            $this->assign('page_info', $page);
        }
        $this->display('aging.index.html');
    }

    //明细
    function detail()
    {
        $key = isset($_REQUEST['id']) ? trim($_REQUEST['id']) : '';
        $data = array();
        $start = date('Y-m-01', strtotime(date("Y-m-d")));
        $end = date('Y-m-d', strtotime(date("Y-m-d")));
        $bdate = empty($_REQUEST['bdate']) ? $start : trim($_REQUEST['bdate']);
        $edate = empty($_REQUEST['edate']) ? $end : trim($_REQUEST['edate']);
        $type = empty($_REQUEST['type']) ? '' : trim($_REQUEST['type']);
        $searchType = empty($_REQUEST['searchType']) ? 'feeFcheckdate' : trim($_REQUEST['searchType']);
        $pageIndex = empty($_REQUEST['pageIndex']) ? 1 : trim($_REQUEST['pageIndex']);
        //$wxNum = empty($_REQUEST['wxNum']) ? '123' : trim($_REQUEST['wxNum']);
        $wxNum = isset($_COOKIE['wxid'])?$_COOKIE['wxid']:'';
        if(empty($wxNum)){
            echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';
            echo "<script>alert('授权未成功');  window.location.href='http://dskc.csrsfwl.com/index.php?app=login'; </script>  ";//使用weixin.php的页面
        }
        if ($this->checkUrl(WEB_SERVICE)) {
            $client = new soapclient(WEB_SERVICE);
            $client->soap_defencoding = 'utf-8';
            $client->decode_utf8 = false;
            $client->xml_encoding = 'utf-8';
            $param = array(
                'json' => '{"pageIndex":"' . $pageIndex . '","key":"' . $key . '","bdate":"' . $bdate . '","edate":"' . $edate . '","type":"' . $type . '","searchType":"' . $searchType . '","wxNum": "' . $wxNum . '"}');
            $result = $client->__Call("AgingInfo", array($param));
            if (is_soap_fault($result)) {
                trigger_error("SOAP Fault: (faultcode: {$result->faultcode}, faultstring: {$result->faultstring})", E_USER_ERROR);
            } else {
                $result = json_decode(json_encode($result->AgingInfoResult), TRUE);
                $result = preg_replace('/([\r\n])/', '', $result);
                $result = json_decode($result, true);
                if ($result['status'] == 1) {
                    $data = $result['result'];
                    $dataCount = $result['dataCount'];
                }

            }
        }
        $this->assign('bdate', $bdate);
        $this->assign('edate', $edate);
        $this->assign('searchType', $searchType);
        $this->assign('type', $type);
        if($data)
        {
            $this->assign('agings', $data);
            $page = $this->_get_page();
            $page['item_count'] = $dataCount;
            $this->_format_pageweb($page);
            $this->assign('page_info', $page);
        }
        $this->display('aging.detail.html');
    }

    //列表更多
    function listmore()
    {
        $UnitID = isset($_REQUEST['id']) ? trim($_REQUEST['id']) : '';
        $data = array();
        $pageIndex = empty($_REQUEST['pageIndex']) ? 1 : trim($_REQUEST['pageIndex']);
        $start = date('Y-m-01', strtotime(date("Y-m-d")));
        $end = date('Y-m-d', strtotime(date("Y-m-d")));
        $bdate = empty($_REQUEST['bdate']) ? $start : trim($_REQUEST['bdate']);
        $edate = empty($_REQUEST['edate']) ? $end : trim($_REQUEST['edate']);
        $type = empty($_REQUEST['type']) ? '' : trim($_REQUEST['type']);
        $searchType = empty($_REQUEST['searchType']) ? 'feeFcheckdate' : trim($_REQUEST['searchType']);
        //$wxNum = empty($_REQUEST['wxNum']) ? '123' : trim($_REQUEST['wxNum']);
        $wxNum = isset($_COOKIE['wxid'])?$_COOKIE['wxid']:'';
        if(empty($wxNum)){
            echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';
            echo "<script>alert('授权未成功');  window.location.href='http://dskc.csrsfwl.com/index.php?app=login'; </script>  ";//使用weixin.php的页面
        }
        if ($this->checkUrl(WEB_SERVICE)) {
            $client = new soapclient(WEB_SERVICE);
            $client->soap_defencoding = 'utf-8';
            $client->decode_utf8 = false;
            $client->xml_encoding = 'utf-8';
            $param = array(
                'json' => '{"pageIndex":"' . $pageIndex . '","bdate":"' . $bdate . '","edate":"' . $edate . '","type":"' . $type . '","searchType":"' . $searchType . '","wxNum": "' . $wxNum . '"}');
            $result = $client->__Call("AgingList", array($param));
            if (is_soap_fault($result)) {
                trigger_error("SOAP Fault: (faultcode: {$result->faultcode}, faultstring: {$result->faultstring})", E_USER_ERROR);
            } else {
                $result = json_decode(json_encode($result->AgingListResult), TRUE);
                $result = preg_replace('/([\r\n])/', '', $result);
                $result = json_decode($result, true);

                if ($result['status'] == 1) {
                    foreach ($result['result'] as $key => $val) {
                        if ($val['UnitID'] == $UnitID) {
                            $data = $val;
                            break;
                        }
                    }
                } else {


                }


            }
        }
        $this->assign('aging', $data);
        $this->display('aging.listmore.html');
    }

    //明细更多
    function infomore()
    {
        $key = isset($_REQUEST['id']) ? trim($_REQUEST['id']) : '';
        $init = isset($_REQUEST['init']) ? trim($_REQUEST['init']) : '';
        $data = array();
        $start = date('Y-m-01', strtotime(date("Y-m-d")));
        $end = date('Y-m-d', strtotime(date("Y-m-d")));
        $pageIndex = empty($_REQUEST['pageIndex']) ? 1 : trim($_REQUEST['pageIndex']);
        $bdate = empty($_REQUEST['bdate']) ? $start : trim($_REQUEST['bdate']);
        $edate = empty($_REQUEST['edate']) ? $end : trim($_REQUEST['edate']);
        $type = empty($_REQUEST['type']) ? '' : trim($_REQUEST['type']);
        $searchType = empty($_REQUEST['searchType']) ? 'feeFcheckdate' : trim($_REQUEST['searchType']);
        //$wxNum = empty($_REQUEST['wxNum']) ? '123' : trim($_REQUEST['wxNum']);
        $wxNum = isset($_COOKIE['wxid'])?$_COOKIE['wxid']:'';
        if(empty($wxNum)){
            echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';
            echo "<script>alert('授权未成功');  window.location.href='http://dskc.csrsfwl.com/index.php?app=login'; </script>  ";//使用weixin.php的页面
        }
        if ($this->checkUrl(WEB_SERVICE)) {
            $client = new soapclient(WEB_SERVICE);
            $client->soap_defencoding = 'utf-8';
            $client->decode_utf8 = false;
            $client->xml_encoding = 'utf-8';
            $param = array(
                'json' => '{"pageIndex":"' . $pageIndex . '","key":"' . $key . '","bdate":"' . $bdate . '","edate":"' . $edate . '","type":"' . $type . '","searchType":"' . $searchType . '","wxNum": "' . $wxNum . '"}');
            $result = $client->__Call("AgingInfo", array($param));
            if (is_soap_fault($result)) {
                trigger_error("SOAP Fault: (faultcode: {$result->faultcode}, faultstring: {$result->faultstring})", E_USER_ERROR);
            } else {
                $result = json_decode(json_encode($result->AgingInfoResult), TRUE);
                $result = json_decode($result, true);
                if ($result['status'] == 1) {
                    foreach ($result['result'] as $k => $val) {
                        if ($val['init'] == $init) {
                            $data = $val;
                            break;
                        }
                    }
                } else {
                    /*  echo $result['result'];*/
                    echo "<script>alert('".$result['result']."'); </script>  ";

                }


            }
        }
        $this->assign('aging', $data);
        $this->display('aging.infomore.html');
    }

}
